package ruifeng.zcj.dig.ui.home;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.OnClick;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.base.BaseBarFragment;
import ruifeng.zcj.dig.base.FragmentInfo;
import ruifeng.zcj.dig.groble.FragmentArgs;
import ruifeng.zcj.dig.ui.base.DepositFragment;
import ruifeng.zcj.dig.ui.forum.NewPostFragment;
import ruifeng.zcj.dig.ui.home.change.ChangeMainFragment;
import ruifeng.zcj.mybase.base.BaseActivity;

/**
 * Created by Administrator on 2016/8/31 0031.
 */
public class HomeFragment extends DepositFragment {
    public static final String FILM_URL = "HomeFragment";

    @Bind(R.id.activity_top_left)
    ImageView mActivityTopLeft;
    @Bind(R.id.activity_top_center)
    TextView mActivityTopCenter;
    @Bind(R.id.activity_top_right)
    ImageView mActivityTopRight;
    @Bind(R.id.activity_top_right_text)
    TextView mActivityTopRightText;
    @Bind(R.id.iv_pic)
    ImageView mIvPic;
    @Bind(R.id.home_fragment_img1)
    ImageView mHomeFragmentImg1;
    @Bind(R.id.home_fragment_text1)
    TextView mHomeFragmentText1;
    @Bind(R.id.home_fragment_relative1)
    RelativeLayout mHomeFragmentRelative1;
    @Bind(R.id.home_fragment_img2)
    ImageView mHomeFragmentImg2;
    @Bind(R.id.home_fragment_text2)
    TextView mHomeFragmentText2;
    @Bind(R.id.home_fragment_relative2)
    RelativeLayout mHomeFragmentRelative2;
    @Bind(R.id.home_fragment_img3)
    ImageView mHomeFragmentImg3;
    @Bind(R.id.home_fragment_text3)
    TextView mHomeFragmentText3;
    @Bind(R.id.home_fragment_relative3)
    RelativeLayout mHomeFragmentRelative3;
    @Bind(R.id.home_fragment_img4)
    ImageView mHomeFragmentImg4;
    @Bind(R.id.home_fragment_text4)
    TextView mHomeFragmentText4;
    @Bind(R.id.home_fragment_relative4)
    RelativeLayout mHomeFragmentRelative4;
    @Bind(R.id.other_fragment_img1)
    ImageView mOtherFragmentImg1;
    @Bind(R.id.other_fragment_text1)
    TextView mOtherFragmentText1;
    @Bind(R.id.home_fragment_relative5)
    RelativeLayout mHomeFragmentRelative5;
    @Bind(R.id.other_fragment_img2)
    ImageView mOtherFragmentImg2;
    @Bind(R.id.other_fragment_text2)
    TextView mOtherFragmentText2;
    @Bind(R.id.home_fragment_relative6)
    RelativeLayout mHomeFragmentRelative6;
    @Bind(R.id.other_fragment_img3)
    ImageView mOtherFragmentImg3;
    @Bind(R.id.other_fragment_text3)
    TextView mOtherFragmentText3;
    @Bind(R.id.home_fragment_relative7)
    RelativeLayout mHomeFragmentRelative7;
    @Bind(R.id.other_fragment_img4)
    ImageView mOtherFragmentImg4;
    @Bind(R.id.other_fragment_text4)
    TextView mOtherFragmentText4;
    @Bind(R.id.home_fragment_relative8)
    RelativeLayout mHomeFragmentRelative8;
    MainActivity2 mainActivity;



    @Override
    protected void initFragmentConfig(View view) {
        mActivityTopCenter.setText("快挖");
        /***
         * Unable to start activity ComponentInfo{ruifeng.zcj.dig/ruifeng.zcj.dig.ui.home.MainActivity}: java.lang.RuntimeException: Unable to bind views for ruifeng.zcj.dig.ui.home.HomeFragment
         * **/
        mActivityTopLeft.setVisibility(View.INVISIBLE);
//        mActivityTopRight.setImageResource(R.drawable.personal_h);


        mHomeFragmentImg1.setImageResource(R.drawable.shopping_home);
        mHomeFragmentText1.setText("商城");
        mHomeFragmentImg2.setImageResource(R.drawable.forum_home);
        mHomeFragmentText2.setText("论坛");
        mHomeFragmentImg3.setImageResource(R.drawable.assessment_home);
        mHomeFragmentText3.setText("评估");
        mHomeFragmentImg4.setImageResource(R.drawable.car_home);
        mHomeFragmentText4.setText("二手车");

        mOtherFragmentImg1.setImageResource(R.drawable.sign_home);
        mOtherFragmentText1.setText("签到");
        mOtherFragmentImg2.setImageResource(R.drawable.recruit_home);
        mOtherFragmentText2.setText("招聘");
        mOtherFragmentImg3.setImageResource(R.drawable.repair_home);
        mOtherFragmentText3.setText("快修");
        mOtherFragmentImg4.setImageResource(R.drawable.trailer_home);
        mOtherFragmentText4.setText("快拖");

        // 切换Fragment的时候需要用到MainActivity
        BaseActivity baseActivity = getBaseActivity();
        mainActivity = (MainActivity2) baseActivity;


        super.initFragmentConfig(view);// 因为子类有一个父类没有的控件


       /* BaseActivity baseActivity = getBaseActivity();
        MainActivity aa = (MainActivity)baseActivity;
        aa.switchFragment(1);*/
    }

    /***
     * 设置缓存页数
     ***/
    public void setScreenPageLimit() {
        mViewPager.setOffscreenPageLimit(mBaseFragmentViewPageAdapter.getCount());
    }

    @Override
    protected void addPage(ArrayList<String> tabTitles, ArrayList<FragmentInfo> fragmentInfos) {
        tabTitles.add("测试下哈");
        fragmentInfos.add(new FragmentInfo(ChangeMainFragment.class, getBundle(1)));
    }

    @Override
    public int getContentView() {
        return R.layout.fragment_home;
    }

    @Override
    protected void onFirstUserVisible() {
//        super.onFirstUserVisible();

    }

    @Override
    protected void onUserVisible() {

    }

    @Override
    protected void onUserInvisible() {

    }

    @Override
    protected void cleanMemory() {

    }


    @OnClick({R.id.activity_top_right, R.id.iv_pic, R.id.home_fragment_relative1, R.id.home_fragment_relative2, R.id.home_fragment_relative3, R.id.home_fragment_relative4, R.id.home_fragment_relative5, R.id.home_fragment_relative6, R.id.home_fragment_relative7, R.id.home_fragment_relative8})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.activity_top_right:
                showSnackBar("我被点击了activity_top_right");

                break;
            case R.id.iv_pic:// 顶部的图片，居中裁剪的那个图片
                showSnackBar("iv_pic");
                break;
            case R.id.home_fragment_relative1:
                if (mainActivity != null) {
                    mainActivity.switchFragment(1);
                }
                break;
            case R.id.home_fragment_relative2:
                if (mainActivity != null) {
                    mainActivity.switchFragment(2);
                }
                break;
            case R.id.home_fragment_relative3:
                if (mainActivity != null) {
                    mainActivity.switchFragment(3);
                }
                break;
            case R.id.home_fragment_relative4:
                if (mainActivity != null) {
                    mainActivity.switchFragment(4);
                }
                break;
            case R.id.home_fragment_relative5:// 签到
                break;
            case R.id.home_fragment_relative6:// 招聘
                FragmentArgs fragmentArgs = new FragmentArgs();
                fragmentArgs.add(FILM_URL, "122");
                //HomAllActivity.launch();
                HomAllActivity.launch(getBaseActivity(), HomeFragment.class, fragmentArgs);
                break;
            case R.id.home_fragment_relative7:// 快修
                break;
            case R.id.home_fragment_relative8:// 快脱
                break;
        }
    }

}
